package com.engr.util;

import com.engr.consts.ResultCodes;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.io.Serializable;

/**
 * 公共响应类
 * @Auther: lzw
 * @Date: 2018/6/4
 */
public class ResponseMessage implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int code;
	private String message;
	private Object data;


	public ResponseMessage(int code, String message, Object data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public static ResponseMessage success(Object data) {
		return new ResponseMessage(ResultCodes.SUCCESS, "SUCCESS", data);
	}

	public static ResponseMessage success() {
		return success("SUCCESS");
	}

    public static ResponseMessage error() {
        return error(ResultCodes.ERROR, "失败");
    }

    public static ResponseMessage error(String message) {
        return error(ResultCodes.ERROR, message);
    }

	public static ResponseMessage error(int code, String message) {
        return new ResponseMessage(code, message, null);
    }
    public static ResponseMessage error(int code, String message, Object data) {
        return new ResponseMessage(code, message, data);
    }

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() throws JsonProcessingException {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
}
